rm(list=ls())
library(SuperLearner)

setwd("/scratch/cds2083")

intOut <- matrix(NA, ncol=7)
for(i in 1:6){
	for(j in 1:10){
	load(paste("col-interv-pscore-REDO-", 	
			i,"-imp",
			j,
			".RData",
			sep=""))

	if(i+j==2){
		intOut <- t(rbind(i,j,
				as.matrix(fitInterventions.pscore$coef)))
				}
	if(i+j>2){
		intOut <- rbind(intOut,
				t(rbind(i,j,
				as.matrix(fitInterventions.pscore$coef))))
				}
}
}
intOut <- as.data.frame(intOut)
write.csv(intOut,
			file="int-wgts.csv",
			row.names=F)

intTitles <- c(	"Employment",
				"Security",
				"Confidence",
				"Depression",
				"Excom. peers",
				"Ties to commander"
				)


pdf(file="int-wgts.pdf", width=9, height=4)
par(mfrow=c(1,6))
for(i in 1:6){
wgt.means <- apply(intOut[intOut$i==i,-c(1,2)], 2, mean)
wgt.mins <- apply(intOut[intOut$i==i,-c(1,2)], 2, min)
wgt.max <- apply(intOut[intOut$i==i,-c(1,2)], 2, max)
par(mar=c(6,2,1,1))
plot	(c(1,2,3,4,5),
		wgt.means,
		ylim=c(0,1),
		axes=F,
		ylab="",
		xlab="",
		main=intTitles[i],
		pch=19,
		cex=1)
segments(	c(1,2,3,4,5),
			wgt.mins,
			c(1,2,3,4,5),
			wgt.max,
			lwd=2)
segments(c(1,2,3,4,5), 
		c(0,0,0,0,0),
		c(1,2,3,4,5),
		c(1,1,1,1,1),
		lty="dotted")
abline(h=0)
axis(1, at=c(1,2,3,4,5),
		c(	"Logit",
			"KRLS",
			"BART",
			"t-reg. logit",
			"SVM"),
		las=2,
		lwd=0,
		line=-1)
if(i==1){axis(2, c(0,.5,1))}	
}
dev.off()

par(mfrow=c(1,6))
for(i in 1:6){
wgt.means <- apply(intOut[intOut$i==i,-c(1,2)], 2, mean)
wgt.sds <- apply(intOut[intOut$i==i,-c(1,2)], 2, sd)
if(i==1)par(mar=c(3,6,1,1))
if(i>1)par(mar=c(3,1,1,1))
plot	(wgt.means, 
		c(1,2,3,4,5),
		xlim=c(0,1),
		axes=F,
		ylab="",
		xlab="",
		main=intTitles[i],
		pch=19)
segments(wgt.means-2*wgt.sds,
			c(1,2,3,4,5),
			wgt.means+2*wgt.sds,
			c(1,2,3,4,5))
abline(h=c(1,2,3,4,5), lty="dotted")
if(i==1){
axis(2, at=c(1,2,3,4,5),
		c(	"Logit",
			"KRLS",
			"BART",
			"t-reg. logit",
			"SVM"),las=1)}
axis(1, c(0,.5,1))		
box()}
